package Solution.problem098.ValidateBinarySearchTree;

import common.TreeNode;

/**
 * @program Leetcode
 * @description:
 * @author: lishangsheng
 * @create: 2019/07/08 15:29
 */
public class Solution {
    public boolean isValidBST(TreeNode root) {
        if (root == null) {
            return true;
        }
        /*边界问题，int的最大值最小值不能满足*/
        return check(root, Long.MIN_VALUE, Long.MAX_VALUE);
    }

    private boolean check(TreeNode root, long min, long max) {
        if(root==null){
            return true;
        }
        /*二叉搜索树没有重复的*/
        if(root.val<=min||root.val>=max){
            return false;
        }
        return check(root.left,min,root.val)&&check(root.right,root.val,max);
    }
}

